package Part6_对象流;

import java.io.Serializable;

/**
 * ClassName: Person
 * Package: IntelliJ IDEA
 * Description:
 * Written by HanXu
 * Create 2024.04.22 23:21
 */

//一、Serializable仅为标识接口，内部没有任何抽象方法需要重写
//二、只是需要声明一个标识ID:serialVersionUID(全局常量)
//三、自定义类的属性也必须是可序列化的：基本数量类型是默认可序列化的、引用数据类型的属性要声明可序列化

//如果某个属性声明为transient（瞬时的）或者static，则不会序列化（不会保存在文件里）

public class Person implements Serializable {

    private static final long serialVersionUID = 3543524L;

    String name;
    int age;

    Account account;


    public Person() {
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public Person(String name, int age, Account account) {
        this.name = name;
        this.age = age;
        this.account = account;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", [account=" + account +
                "] }";
    }
}

class Account implements Serializable{

    private static final long serialVersionUID = 1143424L;

    double account;

    public Account(double account) {
        this.account = account;
    }

    public double getAccount() {
        return account;
    }

    public void setAccount(double account) {
        this.account = account;
    }

    @Override
    public String toString() {
        return " " + account + " ";
    }
}
